﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Objects.DataClasses;

namespace Util
{
	/// <summary>
	/// Dal基类，实现了基本的，常用的方法。
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class Dal<T> where T : EntityObject
	{
		public int GetCount(Func<T, bool> func)
		{
			var list = DalUtil.GetList<T>(func);
			return list == null ? 0 : list.Count;
		}
		public int Add(T t)
		{
			return DalUtil.Add<T>(t);
		}
		public int Add(List<T> t)
		{
			return DalUtil.Add<T>(t);
		}
		public int Update(T t)
		{
			return DalUtil.Update<T>(t);
		}
		public int Delete(int id)
		{
			return DalUtil.Delete<T>(id);
		}
		public int Delete(Func<T, bool> func)
		{
			return DalUtil.Delete<T>(func);
		}
		public T GetSingle(int id)
		{
			return DalUtil.GetSingle<T>(id);
		}
		public T GetSingle(Func<T, bool> func)
		{
			return DalUtil.GetSingle<T>(func);
		}
		public T GetSingleRelated(Func<T, bool> func, string include)
		{
			return DalUtil.GetSingle(func, include);
		}
		public T GetSingleRelated(Func<T, bool> func, string[] includes)
		{
			return DalUtil.GetSingle(func, includes);
		}
		public IList<T> GetList(Func<T, bool> func)
		{
			return DalUtil.GetList<T>(func);
		}
		public IList<T> GetList(Func<T, bool> func, bool asce1, Func<T, object> order1)
		{
			return DalUtil.GetList<T>(func, asce1, order1);
		}
		public IList<T> GetList(Func<T, bool> func, int index, int size)
		{
			return DalUtil.GetList(func, (index - 1) * size, size);
		}
		public IList<T> GetList(Func<T, bool> func, bool asce1, Func<T, object> order1, int index, int size)
		{
			return DalUtil.GetList<T>(func, asce1, order1, (index - 1) * size, size);
		}
		public IList<T> GetList(Func<T, bool> func, bool asce1, Func<T, object> order1, bool asce2, Func<T, object> order2, int index, int size)
		{
			return DalUtil.GetList<T>(func, asce1, order1, asce2, order2, (index - 1) * size, size);
		}
		public IList<T> GetList(Func<T, bool> func, IDictionary<Func<T, object>, bool> dic, int index, int size)
		{
			return DalUtil.GetList<T>(func, dic, (index - 1) * size, size);
		}
		public IList<T> GetListRelated(Func<T, bool> func, string include)
		{
			return DalUtil.GetList(func, include);
		}
		public IList<T> GetListRelated(Func<T, bool> func, string[] includes)
		{
			return DalUtil.GetList(func, includes);
		}
	}
}